package cn.cs.service.impl;

import cn.cs.client.UserInformationWebClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.UserInformationWeb;
import cn.cs.service.UserInformationWebService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class UserInformationWebServiceImpl implements UserInformationWebService {

    @Resource
    private UserInformationWebClient userInformationWebClient;

    public UserInformationWeb getUserInformationWebById(String id) throws Exception {
        return userInformationWebClient.getUserInformationWebById(id);
    }

    public List<UserInformationWeb> getUserInformationWebListByMap(Map<String, Object> param) throws Exception {
        return userInformationWebClient.getUserInformationWebListByMap(param);
    }

    public Integer getUserInformationWebCountByMap(Map<String, Object> param) throws Exception {
        return userInformationWebClient.getUserInformationWebCountByMap(param);
    }

    public Integer addUserInformationWeb(UserInformationWeb userInformationWeb) throws Exception {
        userInformationWeb.setCreateDate(new Date());
        return userInformationWebClient.insertUserInformationWeb(userInformationWeb);
    }

    public Integer modifyUserInformationWeb(UserInformationWeb userInformationWeb) throws Exception {
        return userInformationWebClient.updateUserInformationWeb(userInformationWeb);
    }

    public Integer deleteUserInformationWebById(String id) throws Exception {
        return userInformationWebClient.deleteUserInformationWebById(id);
    }

    public Page<UserInformationWeb> queryUserInformationWebPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = userInformationWebClient.getUserInformationWebCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<UserInformationWeb> userInformationWebList = userInformationWebClient.getUserInformationWebListByMap(param);
        page.setRows(userInformationWebList);
        return page;
    }

}
